package casa.depesos.app.com.activity;

import android.os.Bundle;

import androidx.annotation.Nullable;

import casa.depesos.app.com.R;
import casa.depesos.app.com.databinding.ActivityOkBinding;
import casa.depesos.app.com.frag.NetFailFragment;
import casa.depesos.app.com.http.ReqCallback;
import casa.depesos.app.com.http.bean.GetCodeBean;
import casa.depesos.app.com.http.req.OkInfoReq;
import casa.depesos.app.com.utils.Report;
import casa.depesos.app.com.utils.Utils;

public class OkActivity extends BaseActivity {

    ActivityOkBinding binding;
    final String title = "Resultado de la solicitud";

    @Override
    protected boolean needPadding() {
        return false;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityOkBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        binding.top.back.setOnClickListener(v -> finish());
        binding.top.title.setText(title);
        binding.top.top.setPadding(0, Utils.getStatusBarHeight(this), 0, 0);

        binding.take.setOnClickListener(view -> {
            Report.click("ACTION_PP_009");
            finish();
        });

        Report.show("ACTION_PP_008");
        getData();
    }

    public void getData() {
        showLoading();
        clearFragment(getSupportFragmentManager());
        new OkInfoReq().req(new ReqCallback<GetCodeBean>() {
            @Override
            public void callback(boolean success, GetCodeBean bean) {
                hideLoading();
                if (success) {
                    String str = binding.tv.getText().toString();
                    str = String.format(str, Utils.formatNoFloat(bean.data.toString(), true));
                    binding.tv.setText(str);
                } else if (bean == null) {
                    replaceFragment(R.id.frame, new NetFailFragment().setTitle(title));
                }
            }
        });
    }
}
